<template>
  <section>
    <el-form label-width="100px">
      <el-form-item label="选择公司：">
        <el-select size="mini" value-key="id" v-model="selCompany">
          <el-option v-for="company in companyList" :key="company.id" :value="company" :label="company.companyName"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <el-tabs v-model="selDepartment" type="border-card">
      <el-tab-pane :label="department.name" :name="department.name" v-for="department in departmentList" :key="department.id">
        <activity-show :department="department"></activity-show>
      </el-tab-pane>
    </el-tabs>
  </section>
</template>

<script>
  import activityShow from './activityShow'
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import Vue from 'vue'//后续添加属性，需要vue联动
  import errHandler from '@/assets/errHandler'
  export default {
    name: "index",
    components: {activityShow},
    data() {
      return {
        selCompany:null,
        loading:false,
        totalPage:0,
        companyList:null,
        departmentList:null,
        selDepartment:''
      }
    },
    created(){
      //获取公司列表
      this.getCompanyList()
    },
    computed:{
    },
    watch: {
      selCompany(nv,ov){
        if(nv){
          //加载公司下的部门列表
          this.getDepartmentList(nv.id)
        }
      }
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      text(){
        this.fetch({name:"getActivity",data:{id:6}})
          .then(res=>{
            console.log('获取到的活动————————————',res)
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      getCompanyList(){
        this.fetch({name:"getCompanyList"})
          .then(res=>{
            console.log(res)
            this.companyList=res
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      getDepartmentList(companyId){
        this.fetch({name:"getDepartmentList",data:{companyId}})
          .then(res=>{
            console.log(res)
            this.departmentList=res
            this.selDepartment=res[0].name
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
    }
  }
</script>

<style scoped>

</style>
